package com.fire.social.service.impl;

import com.fire.social.entity.node.Content;
import com.fire.social.entity.node.User;
import com.fire.social.mapper.ContentMapper;
import com.fire.social.mapper.FollowMapper;
import com.fire.social.service.ContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class ContentServiceImpl implements ContentService {

    @Autowired
    private ContentMapper contentMapper;
    @Autowired
    private FollowMapper followMapper;


    @Override
    public Content createContent(String account, String publisher, String publisherImg, String title, String content, String relatedHobby, Long hobbyid, String imgUrl) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = format.format(new Date());
        Content entity = contentMapper.createContent(account, publisher, publisherImg, title, content, relatedHobby, hobbyid, imgUrl, time);
        return entity;
    }

    @Override
    public void findFriendContent(User user, Map<String, Object> map) {
        Long myFollowNum = followMapper.countIFollow(user.getAccount());
        Long followMeNum = followMapper.countFollowMe(user.getAccount());
        // 读取动态内容
        List<Content> contentList = contentMapper.getFriendContents(user.getAccount());
        map.put("shares", contentList);
        map.put("user", user);
        map.put("myfollowing", myFollowNum);
        map.put("follower", followMeNum);
        map.put("index", "发现动态");
        map.put("title", "好友动态");
    }

    @Override
    public void findContentByHobby(User user, Map<String, Object> map) {
        Long myFollowNum = followMapper.countIFollow(user.getAccount());
        Long followMeNum = followMapper.countFollowMe(user.getAccount());

        List<Content> contentList = contentMapper.findContentByHobby(user.getAccount());
        map.put("shares", contentList);
        map.put("user", user);
        map.put("myfollowing", myFollowNum);
        map.put("follower", followMeNum);
        map.put("index", "发现动态");
        map.put("title", "好友动态");
    }
}
